//
//  TSWebCacheViewController.m
//  AppCommonJSCollect
//
//  Created by ciyouzen on 2019/4/17.
//  Copyright © 2019 dvlproad. All rights reserved.
//

#import "TSWebCacheViewController.h"
#import <WebViewJavascriptBridge/WebViewJavascriptBridge.h>

@interface TSWebCacheViewController () {
    
}
@property (nonatomic, strong) WebViewJavascriptBridge *javascriptBridge;

@end

@implementation TSWebCacheViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    NSString *localHtmlUrl = [[NSBundle mainBundle] pathForResource:@"test_oa_h5js.html" ofType:nil];
//    [self reloadLocalWebWithUrl:localHtmlUrl]; //加载本地网页
    
//    NSString *baseUrl = @"http://localhost";
    NSString *baseUrl = @"https://dvlproad.github.io";
    NSString *path = @"Architecture架构/h5_native_interacte/h5js/dvlp_h5js_demo.html";
    path = [path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *Url = [NSString stringWithFormat:@"%@/%@", baseUrl,path];
    NSLog(@"Url = %@", Url);
    [self reloadNetworkWebWithUrl:Url networkEnable:YES];
    
    [self.javascriptBridge registerHandler:@"commonShare" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSLog(@"commonShare data = %@", data);
    }];
    
    [self.javascriptBridge registerHandler:@"commonShowShare" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSLog(@"commonShowShare data = %@", data);
    }];
}

#pragma mark - getters & setters
- (WebViewJavascriptBridge *)javascriptBridge {
    if (!_javascriptBridge) {
        _javascriptBridge = [WebViewJavascriptBridge bridgeForWebView:self.webView];
        [_javascriptBridge setWebViewDelegate:self.webView];
    }
    return _javascriptBridge;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
